package com.lhjmall.coupon.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lhjmall.coupon.entity.UsercouponEntity;
import com.lhjmall.coupon.service.UsercouponService;
import com.lhjmall.common.utils.PageUtils;
import com.lhjmall.common.utils.R;



/**
 *
 *
 * @author longhaijin
 * @email 287245878@qq.com
 * @date 2021-03-11 10:05:32
 */
@RestController
@RequestMapping("coupon/usercoupon")
public class UsercouponController {
    @Autowired
    private UsercouponService usercouponService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("coupon:usercoupon:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = usercouponService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("coupon:usercoupon:info")
    public R info(@PathVariable("id") Integer id){
		UsercouponEntity usercoupon = usercouponService.getById(id);

        return R.ok().put("usercoupon", usercoupon);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("coupon:usercoupon:save")
    public R save(@RequestBody UsercouponEntity usercoupon){
		usercouponService.save(usercoupon);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("coupon:usercoupon:update")
    public R update(@RequestBody UsercouponEntity usercoupon){
		usercouponService.updateById(usercoupon);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("coupon:usercoupon:delete")
    public R delete(@RequestBody Integer[] ids){
		usercouponService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 信息
     */
    @RequestMapping("/member/coupon")
    //@RequiresPermissions("coupon:usercoupon:info")
    public R memberCoupon(@PathVariable("userId") Integer userId){
		UsercouponEntity usercoupon = usercouponService.getById(1);

        return R.ok().put("usercoupon", usercoupon);
    }


    /**
     * 发送优惠券
     */
    @RequestMapping("/sendCoupon/{userId}")
    //@RequiresPermissions("coupon:usercoupon:save")
    public R sendCoupon(@PathVariable("userId") Integer userId){
		usercouponService.sendCoupon(userId);
        return R.ok();
    }

}
